function [modelToReturn] = init_model(cobraModel)
    
    [modelToReturn] = check_model_for_KEGG_data(cobraModel);

    function [model] = check_model_for_KEGG_data(model)
        tStart = tic;

        metNames = model.metNames;
        metKEGGID = model.metKEGGID;
        metFormulas = model.metFormulas;

        return_values = '';
        
        metaboliteKEGGIDs_KEGGID  = cell(length(metKEGGID),1);
        metaboliteKEGGIDs_METs    = cell(length(metKEGGID),1);
        metaboliteKEGGIDs_FORMULA = cell(length(metKEGGID),1);

        percentEmptyKEGGID = 0;
        percentEmptyKEGGIDByNameFormula = 0;
       
        emptyKEGGID = 0;
        for i = 1:length(metKEGGID)
            if ~isempty(metKEGGID{i})
               metaboliteKEGGIDs_KEGGID(i) = cellstr(metKEGGID{i});
            else
                emptyKEGGID = emptyKEGGID + 1;
            end
        end   
        percentEmptyKEGGID = emptyKEGGID * 100 / length(metKEGGID);

        disp('percent of empty keggid by model.keggid is:');
        disp(percentEmptyKEGGID);

        totalCost=0;
        treshholdForMetName = 10;
        treshholdForMetFormula = 3;
         
        h = waitbar(0,'Please wait... Looking for KEGGIDs');
      
        for i = 1:length(metNames)
            waitbar(i/length(metNames),h, [num2str(i), ' metabolites of ', num2str(length(metNames)), ' total' ])
            drawnow update
            if isempty(metKEGGID{i})
                if ~isempty(metNames{i})
                    [metaboliteKEGGID, cost] = get_kegg_id_by_metName(metNames{i}, treshholdForMetName);
                    if isempty(metaboliteKEGGID)
                        [metaboliteKEGGID, cost] = get_kegg_id_by_metFormula(metFormulas{i}, treshholdForMetFormula);
                    end
                    totalCost = totalCost + cost;
                end
                metaboliteKEGGIDs_FORMULA(i) = cellstr(metaboliteKEGGID);
            end
        end
        close(h)
        
        emptyKEGGID=0;
        
        for i=1:length(metaboliteKEGGIDs_FORMULA)
            if isempty(metaboliteKEGGIDs_FORMULA{i})
                emptyKEGGID = emptyKEGGID + 1;
            end
        end
        percentEmptyKEGGIDByNameFormula = emptyKEGGID * 100 / length(metKEGGID);
        
        disp('percent of empty keggid by model.Name and model.Formula is:');
        disp(percentEmptyKEGGIDByNameFormula);

        disp('total costs of all metabolites:');
        disp(strcat(num2str(totalCost),' of ',num2str(length(metKEGGID)*15)));
       
        if percentEmptyKEGGIDByNameFormula < percentEmptyKEGGID
            returnKEGGIDs = metaboliteKEGGIDs_FORMULA;
        else
            returnKEGGIDs = metaboliteKEGGIDs_KEGGID;
        end
        model = add_kegg_ids_to_model(model, returnKEGGIDs);
        
        tElapsedFillMOdelWIthKEGGIDs = toc(tStart)  
    end

    function modelToFill = add_kegg_ids_to_model(modelToFill, kegg_ids)
        for i=1:length(modelToFill.metKEGGID)
            try
                if ~isempty(kegg_ids{i}) 
                    modelToFill.metKEGGID(i) = kegg_ids(i);
                end
            catch err
                disp(err);
            end
        end
    end    
end